﻿using System.Collections.Generic;

namespace FluentWebRequest
{
    internal class RequestDataBuilder : IRequestDataBuilder
    {
        private readonly string _url;
        private IDictionary<string, string> _requestItems;
        private readonly IRequestMethodFactory _requestMethodFactory;

        public RequestDataBuilder(string url)
            : this(new RequestMethodFactory(), url)
        {
        }

        public RequestDataBuilder(IRequestMethodFactory requestMethodFactory, string url)
        {
            _requestMethodFactory = requestMethodFactory;
            _url = url;
            _requestItems = new Dictionary<string, string>();
        }

        public IRequestItem Item
        {
            get
            {
                return new RequestItem(this, _url, _requestItems);
            }
        }

        public string GetDataFromUrl(RequestMethodType type)
        {
            return _requestMethodFactory.GetDataFromUrl(_url, string.Empty, type);
        }

        public IRequestDataBuilder ReplaceRequestItems(IDictionary<string, string> requestItems)
        {
            _requestItems = requestItems;

            return this;
        }
    }
}